package com.iknow;

import android.app.Activity;
import android.app.AlertDialog.Builder;
import android.app.Application;
import android.app.NotificationManager;
import android.content.ComponentName;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
import android.content.res.Configuration;
import android.database.DataSetObservable;
import android.graphics.Typeface;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.preference.PreferenceManager;
import com.iknow.activity.RegisterActivity;
import com.iknow.app.IKnowSystemConfig;
import com.iknow.db.IKnowDataBase;
import com.iknow.file.CacheSystem;
import com.iknow.image.ProfileImageCacheManager;
import com.iknow.net.translate.IKTranslateManager;
import com.iknow.ui.model.IKPageAdapter;
import com.iknow.util.Loger;
import com.iknow.util.StringUtil;

public class IKnow extends Application
{
  public static DialogInterface.OnClickListener DialogClickListener;
  public static Typeface FACE_PRON;
  public static final String LOGIN_STARTED = "login_start";
  private static final Intent SERVICE_INTENT = new Intent();
  public static final String XMPP_LOG_OUT_ACTION = "LOGOUT";
  public static final String XMPP_MAIN_ACTION = "MAIN_UI_STARTED";
  public static final String XMPP_REGISTER_ACTION = "REGISGER_STARTED";
  public static final int defultTextSize = 16;
  public static IKnowApiV4 mApi;
  public static CacheSystem mCacheSystem;
  public static Context mContext;
  public static IKnowDataBase mIKnowDataBase;
  public static NotificationManager mNotificationManager;
  public static SharedPreferences mPref;
  public static ProfileImageCacheManager mProfileImageCacheManager;
  public static IKnowSystemConfig mSystemConfig;
  public static IKTranslateManager mTranslateManager;
  public static User mUser;
  public static float textLight;
  public static int textSize;
  public final String PACKAGE_NAME;
  private final String TAG = "iKnow Application";
  private boolean mIsAccountConfigured;
  private boolean mIsBinded;
  private boolean mIsConnected;
  private boolean mPepEnabled;
  private final PreferenceListener mPreferenceListener;

  static
  {
    SERVICE_INTENT.setComponent(new ComponentName("com.iknow", "com.iknow.xmpp.service.IKnowXmppService"));
    FACE_PRON = null;
    textSize = -1;
    textLight = 0.5F;
    mNotificationManager = null;
    DialogClickListener = new DialogInterface.OnClickListener()
    {
      public void onClick(, int paramInt)
      {
        switch (paramInt)
        {
        default:
        case -1:
        case -2:
        }
        while (true)
        {
          while (true)
          {
            paramDialogInterface.dismiss();
            return;
            IKnow.startRegisterActivity("login");
          }
          IKnow.startRegisterActivity(null);
        }
      }
    };
  }

  public IKnow()
  {
    this.PACKAGE_NAME = "com.iknow";
    this.mPreferenceListener = new PreferenceListener(this, null);
  }

  public static boolean IsNetAviable()
  {
    boolean bool;
    NetworkInfo localNetworkInfo = ((ConnectivityManager)mContext.getSystemService("connectivity")).getActiveNetworkInfo();
    if (localNetworkInfo == null)
      bool = false;
    while (true)
    {
      return bool;
      bool = localNetworkInfo.isAvailable();
    }
  }

  public static boolean IsUserRegister()
  {
    int i;
    String str = mSystemConfig.getString("register");
    if ((!(StringUtil.isEmpty(str))) && (str.equalsIgnoreCase("1")))
      i = 1;
    while (true)
    {
      return i;
      i = 0;
    }
  }

  public static boolean checkIsBindingUser(Context paramContext)
  {
    int i;
    if (!(IsUserRegister()))
    {
      startRegisterActivity("login");
      i = 0;
    }
    while (true)
    {
      return i;
      i = 1;
    }
  }

  public static void exitSystem()
  {
  }

  public static DataSetObservable getDataSetObservable(Object paramObject)
  {
    return null;
  }

  public static int getTextSize()
  {
    if (textSize < 0)
      textSize = mSystemConfig.getBook_TextSize();
    return textSize;
  }

  public static void setLight(Activity paramActivity)
  {
  }

  public static void setTextSize(IKPageAdapter paramIKPageAdapter, int paramInt)
  {
    textSize = paramInt;
    paramIKPageAdapter.notifyDataSetChanged();
  }

  public static void setUser(User paramUser)
  {
    mUser = null;
    mUser = paramUser;
  }

  public static void showConfigDialog(Context paramContext)
  {
    AlertDialog.Builder localBuilder = new AlertDialog.Builder(paramContext);
    localBuilder.setTitle(2131361795);
    localBuilder.setMessage(2131361883);
    localBuilder.setPositiveButton(2131361824, DialogClickListener);
    localBuilder.setNegativeButton(2131361823, DialogClickListener);
    localBuilder.setCancelable(true);
    localBuilder.show();
  }

  public static void startRegisterActivity(String paramString)
  {
    Intent localIntent = new Intent(mContext, RegisterActivity.class);
    if (paramString != null)
      localIntent.putExtra("action", paramString);
    localIntent.addFlags(268435456);
    mContext.startActivity(localIntent);
  }

  public boolean isAccountConfigured()
  {
    return this.mIsAccountConfigured;
  }

  public boolean isConnected()
  {
    return this.mIsConnected;
  }

  public boolean isPepEnabled()
  {
    return this.mPepEnabled;
  }

  public boolean isSessionBinded()
  {
    return this.mIsBinded;
  }

  public void onConfigurationChanged(Configuration paramConfiguration)
  {
    super.onConfigurationChanged(paramConfiguration);
  }

  public void onCreate()
  {
    String str2;
    int i;
    super.onCreate();
    Loger.i("iKnow Application", "IKnow Application craete!!");
    mContext = getApplicationContext();
    mNotificationManager = (NotificationManager)getSystemService("notification");
    mSystemConfig = new IKnowSystemConfig(this);
    mPref = PreferenceManager.getDefaultSharedPreferences(this);
    mPref.registerOnSharedPreferenceChangeListener(this.mPreferenceListener);
    mApi = new IKnowApiV4();
    mIKnowDataBase = new IKnowDataBase(this);
    mTranslateManager = new IKTranslateManager(this);
    mCacheSystem = new CacheSystem(this);
    mProfileImageCacheManager = new ProfileImageCacheManager();
    String str1 = "";
    User localUser = mIKnowDataBase.getUser();
    if (localUser != null)
    {
      str2 = StringUtil.getMD5String(localUser.getEmail()) + "@" + "imiknow.com";
      mSystemConfig.setString("account_username", str2);
      if (StringUtil.isEmpty(str1))
        str1 = "111111";
      mSystemConfig.setString("account_password", localUser.getPassword());
      if ((!("".equals(str2))) && (!("".equals(str1))))
        break label275;
      i = 0;
    }
    while (true)
    {
      while (true)
      {
        this.mIsAccountConfigured = i;
        if (this.mIsAccountConfigured)
          startService(SERVICE_INTENT);
        return;
        str2 = mPref.getString("account_username", "");
        str1 = mPref.getString("account_password", "");
      }
      label275: i = 1;
    }
  }

  public void setConnected(boolean paramBoolean)
  {
    this.mIsConnected = paramBoolean;
  }

  public void setPepEnabled(boolean paramBoolean)
  {
    this.mPepEnabled = paramBoolean;
  }

  public void setSessionBinded(boolean paramBoolean)
  {
    this.mIsBinded = paramBoolean;
  }

  private class PreferenceListener
  implements SharedPreferences.OnSharedPreferenceChangeListener
  {
    public void onSharedPreferenceChanged(, String paramString)
    {
      IKnow localIKnow;
      boolean bool;
      if (("account_username".equals(paramString)) || ("account_password".equals(paramString)))
      {
        String str1 = IKnow.mPref.getString("account_username", "");
        String str2 = IKnow.mPref.getString("account_password", "123456");
        localIKnow = this.this$0;
        if ((!("".equals(str1))) && (!("".equals(str2))))
          break label81;
        bool = false;
      }
      while (true)
      {
        IKnow.access$0(localIKnow, bool);
        return;
        label81: bool = true;
      }
    }
  }
}